package com.itheima.controller;

import com.itheima.exception.CustomException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@Controller
@RequestMapping("/error")
public class UserController {

    @RequestMapping("/aa")
    public String aa(Model model){
        System.out.println(1/0);
        //添加模型数据
        model.addAttribute("msg", "test model");
        model.addAttribute("nowDate", new Date());
        //通过控制器方法的返回值  指定视图页面的
        return "message";
    }

    @RequestMapping("/bb")
    public String bb(Model model,String username ,String password){
        if("admin".equals(username) && "123".equals(password)){

        }else{
            //throw 抛出异常
            throw new CustomException("用户名或者密码错误!!!");
        }
        //添加模型数据
        model.addAttribute("msg", "test model");
        model.addAttribute("nowDate", new Date());
        //通过控制器方法的返回值  指定视图页面的
        return "message";
    }

}
